<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%>
<c:set var="path" value="..${ctx}/common/define"/>

<div class="pageContent" >
	<div class="panelBar">
		<ul class="toolBar">
			<li><a class="add" onclick="addaction('添加操作');" title="添加操作"><span>添加</span></a><br /><br /></li>
			<li class="line">line</li>
			<li><a class="add" onclick="addunit('search','添加查询操作');" title="添加查询操作单元"><span>添加查询操作单元</span></a><br /><br /></li>
			<li class="line">line</li>
			<li><a class="add" onclick="addunit('update','添加更新操作');" title="添加更新操作单元"><span>添加更新操作单元</span></a><br /><br /></li>
			<li class="line">line</li>
			<li><a class="add" onclick="addunit('define','添加自定义操作');" title="添加自定义操作单元"><span>添加自定义操作单元</span></a><br /><br /></li>
			<li class="line">line</li>
			<li><a class="edit" onclick="modify();" title="修改操作" ><span>修改</span></a></li>
			<li class="line">line</li>
			<li><a class="edit" onclick="saveall();" title="保存所有"><span>保存</span></a></li>
			<li class="line">line</li>
			<li><a class="delete" onclick="deleteAction();"><span>删除</span></a></li>
		</ul>
	</div>
	<table class="table" width="100%" layoutH="138">
		<thead>
			<tr>
				<th width="60">操作名称</th>
				<th width="80">视图名称</th>
				<th width="240">描述</th>
			</tr>

		</thead>
			<tbody>
			<c:if test="${! empty bean.actions}">
			<c:forEach var="vo" items="${bean.actions}">
			<c:set var="data" value="${vo.value}" />
			<tr target="params" rel="action,${data.name}" class="base_define_action_list_tr">
				<td>${data.name}</td>
				<td>${data.jsp}</td>
				<td>${data.description}</td>
			</tr>
			</c:forEach>
			</c:if>
			<c:if test="${! empty bean.actionUnits}">
			<c:forEach var="vo" items="${bean.actionUnits}">
			<c:set var="data" value="${vo.value}" />
			<tr target="params" rel="unit,${data.name}" class="base_define_action_list_tr">
				<td>${data.name}</td>
				<td></td>
				<td>${data.description}</td>
			</tr>
			</c:forEach>
			</c:if>
		</tbody>
	</table>

</div>

<script type="text/javascript">
/**
 * dialog上的表单提交回调函数
 * 服务器转回navTabId，可以重新载入指定的navTab. statusCode=DWZ.statusCode.ok表示操作成功, 自动关闭当前dialog
 * form提交后返回json数据结构,json格式和navTabAjaxDone一致
 */
function dialogAjaxDone(json){
	DWZ.ajaxDone(json);
	if (json.statusCode == DWZ.statusCode.ok){
		// alert(json.callbackType);
		if(json.callbackType){
			navTab.reload("${path}/paging.html?tableName=bs_role&jsp=base/power/role/role_list");//刷新
			setTimeout(function(){$.pdialog.closeCurrent();}, 100);
		}
	}
}

function addaction(title){
	var url = "${path}/addaction.html";
	navTab.openTab("base_define_add_action", url, { title:title, fresh:false, data:{} });
}

function addunit(action, title){
	var url = "${path}/addunit.html?state=stand&type=" + action;
	$.pdialog.open(url, "base_define_add_unit", title,{width:800,height:460,mask:true,maxable:false,resizable:false});
}

function modify(){
	var rel = '';
	$('.base_define_action_list_tr').each(function(){
		// alert($(this).attr('rel'));
		if($(this).hasClass("selected")){
			rel = $(this).attr('rel');
		}
	});
	if(rel==''){
		alertMsg.warn('请先选择一条数据！');
	}else{
		var arr = rel.split(","); //字符分割 
		if(arr[0] == "action"){
			var url = "${path}/getAction.html";
			var title = "更新操作";
			navTab.openTab("base_define_modify_action", url, { title:title, fresh:false, data:{name:arr[1]} });
		}else if(arr[0] == "unit"){
			var url = "${path}/getUnit.html?name=" + arr[1];
			var title = "更新操作单元";
			$.pdialog.open(url, "base_define_modify_unit", title,{width:800,height:460,mask:true,maxable:false,resizable:false});
		}
	}
}

function saveall(){
	var url = "${path}/saveAll.html";
	$.ajax({
		type: "post", url: url,
		success: function(json){
			var result = JSON.parse(json); 
			if (result.statusCode == DWZ.statusCode.ok){
				alertMsg.correct(result.message);
			}
		},
		error: function(){
			alertMsg.error('系统错误，请联系管理员！');
		}
	});
}

function deleteAction(){
	var rel = '';
	$('.base_define_action_list_tr').each(function(){
		if($(this).hasClass("selected")){
			rel = $(this).attr('rel');
		}
	});
	if(rel==''){
		alertMsg.warn('请先选择一条数据！');
	}else{
		alertMsg.confirm("确定要删除吗?", {
			okCall: function(){
				var url = "${path}/delete.html?type=action&id=" + rel;
				$.ajax({
					type: "post", url: url,
					success: function(json){
						alertMsg.correct(json.msg);
						var url = "${path}/list.html";
						navTab.reload(url);
					},
					error: function(){
						alertMsg.error('系统错误，请联系管理员！');
					}
				});
			}
		});
	}
}

</script>


